#ifndef _GEOMODEL_H_
#define _GEOMODEL_H_

#include "../../tools/Point.h"
#include "../../draw/Color.h"
#include "../../draw/DrawObject.h"

#include <vector>
#include <map>

/**
	The model that holds all geometry data. This includes faces and vertices with position and color.
	Currently only does colored polygons, no textures
*/
class GeometryModel {
	/**	A single vertex used for drawing	*/
	struct GeoModelVertex {
	public:
		fVec3D pos;		//The coordinate of where to draw
		Color color;		//The color to draw
		GeoModelVertex(double x = 0, double y = 0, double z = 0, double r = 0, double g = 0, double b = 0, double a = 1): pos(x,y,z), color(r,g,b,a)	{}
	 
		void draw();
	};

	/**	A face to render. References loaded vertices */
	class GeoModelFace {
		std::vector<GeoModelVertex*> vertices;	//List of vertices to draw, as well as their ordering
		void iterateOverVerts();				//Loop to make gl calls on each vertex
		
	public:
		GeoModelFace(int maxVerts = -1): vertices()	{	setMaxVertices(maxVerts);	}
	//	GeoModelFace(const GeoModelFace& o);		//TODO define this
	
		//Sets the capacity of the vertices array if we know it before hand
		bool setMaxVertices(unsigned);
	
		void draw();
	
		//Adds a vertex into this face's list
		void addVertex(GeoModelVertex*);
	};

	//The map if vertices with their ids
	std::map<unsigned, GeoModelVertex> vertices;	//Yes save by instance, not pointer
	
	//The list of all faces of this model
	std::vector<GeoModelFace> faces;	//Yes save by instance, not pointer
	
	//Gets a reference for a new face instance to set
	GeoModelFace& newFace();
	
	//Sets the capacity of the faces array if we know how big it will be in the end
	bool setMaxFaces(unsigned);
public:
	GeometryModel(): vertices(),faces(), localPosition(), localRotation(), scale(1,1,1)		{}
	
	void draw();	//Draw this model
	
	//Loads the model from the given xml file
	void load(const char* filename);
	
	//Gets the axis aligned back, left, lowest point	(min point)
	fVec3D getBackLowerLeft();
	//Gets the axis aligned front, right, highest point	(max point)
	fVec3D getFrontUpperRight();
	
	fVec3D localPosition;		//Where to translate to before drawing
	fVec3D localRotation;		//The rotations before drawing
	fVec3D scale;				//What scale to draw at in each axis
};

#endif
